package com.rockfalldefence.sw.embark.client.page;

import net.binarymuse.gwt.client.ui.wizard.WizardPage;

import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.ValueBoxBase.TextAlignment;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.rockfalldefence.sw.embark.client.RDEmbarkContext;

public class CalcoloSpanciamentoPage extends WizardPage<RDEmbarkContext> {
	public static final PageID PAGEID = new PageID();
	private FlowPanel panel;
	private TextBox tbVerifica;
	private ListBox dropBox;
	
	public CalcoloSpanciamentoPage() {
		panel = new FlowPanel();
	    panel.add(new HTML("<h1>Verifica dello Spanciamento del Rilevato (SLE)</h1><br/>"));

	    Image img = new Image("images/trapezio_spanciamento.png");
	    dropBox = new ListBox(false);
	    dropBox.addChangeHandler(new ChangeHandler() {
			@Override
			public void onChange(ChangeEvent event) {
				computeVerify();
			}
		});
	    dropBox.addItem("TT 045 SAMP => 45 kN/m","45");
	    dropBox.addItem("TT 060 SAMP => 60 kN/m","60");
	    dropBox.addItem("TT 090 SAMP => 90 kN/m","90");
	    dropBox.addItem("TT 120 SAMP => 120 kN/m","120");
	    dropBox.addItem("TT 160 SAMP => 160 kN/m","160");
	    //t.setWidget(1, 1, dropBox);
	    dropBox.setItemSelected(1, true);
	    
	    HorizontalPanel hp = new HorizontalPanel();
	    VerticalPanel vp = new VerticalPanel();
	    vp.add(img);
	    vp.add(new HTML("<h3>Geogriglia proposta</h3>"));
	    vp.add(dropBox);
	    hp.add(vp);
	    //t.setHTML(5, 2, "&nbsp;");
	    vp = new VerticalPanel();
	    vp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
	    vp.add(new HTML("<h2 align='center'>Spanciamento δ < 0.2*b</h2>"));
	    img = new Image("images/spanciamento.png");
	    vp.add(img);
	    tbVerifica = new TextBox();
	    tbVerifica.setReadOnly(true);
	    tbVerifica.setText("VERIFICATO");
	    tbVerifica.setAlignment(TextAlignment.CENTER);
	    vp.add(tbVerifica);
	    hp.add(vp);
	    panel.add(hp);
	    
	    
	}

	protected void computeVerify()
	{
		String sVal = dropBox.getValue(dropBox.getSelectedIndex());
		if( sVal.equals("45"))
		{
		    tbVerifica.setText("NON VERIFICATO");
		}
		else
		{
		    tbVerifica.setText("VERIFICATO");	
		}
	}

	@Override
	public Widget asWidget() {
		
		return panel;
	}

	@Override
	public PageID getPageID() {
		return PAGEID;
	}

	@Override
	public String getTitle() {
		return "Spanciamento";
	}

}
